module test_sph_meson
    use seakeeping_utils
    use seakeeping_filesystem
    type meson_env
        logical :: is_meson_devenv
        character(:), allocatable :: path
    contains
        procedure :: setup_path
        procedure :: ensure_env
    end type meson_env
    type(meson_env) :: env
contains
    !> Get current working directory <br>
    !> 获取当前工作路径
    impure function pwd()
        character(:), allocatable :: pwd
        character(256) :: pwd_
        call getcwd(pwd_) ! GNU extension, IFORT extension
        pwd = trim(pwd_)
    end function pwd
    !> 判断是否为meson环境
    subroutine ensure_env(this)
        class(meson_env), intent(inout) :: this
        if (len(optenv('MESON_DEVENV', '')) /= 0) then
            this%is_meson_devenv = .true.
        else
            this%is_meson_devenv = .false.
        end if
    end subroutine ensure_env
    !> 确定当前路径与starter路径
    subroutine setup_path(this)
        class(meson_env), intent(inout) :: this
        character(:), allocatable :: path
        integer :: ik
        path = pwd()
        ik = index(path, 'starter')
        this%path = path(1:ik-1)//'starter'.join.'example'
    end subroutine setup_path
end module test_sph_meson
